#!/bin/bash

# AMyCMS - Asterisk and MySQL Cluster Management Suite
# This script is part of the Asterisk and MySQL Cluster configuration and management suite for Debian Lenny
# Please see the README for more info
# This script installs and configures MySQL Cluster for Debian Lenny
# IMPORTANT!!!!
# This script is the client script, only run it on your NON-MANAGEMENT nodes!!
# Run the mgm-install.sh file on your management node BEFORE running this on your client nodes!!
#
# Copyright Phil Haddad 2009 

# IP address scheme (change to suit your cluster)

node1="192.168.70.150"
node2="192.168.70.151"
node3="192.168.70.152"
node4="192.168.70.153"
mgm1="192.168.70.162" # MySQL Cluster Management Node 

# install packages

apt-get install flex make gcc g++ libncurses5-dev sox libmysqlclient15-dev mysql-server mysql-client php5 php5-cli
# make sure we stop the mysql deamon
/etc/init.d/mysql stop

# create config.ini - adjust to suit your cluster

echo "[ndbd default]
NoOfReplicas=4

[mgm]
Hostname=$mgm1

[mysqld default]
[ndb_mgmd default]
[tcp default]

[ndbd]
HeartbeatIntervalDbDb=600
HeartBeatIntervalDbApi=600
Hostname=$node1
DataDir=/var/lib/mysql-cluster
DataMemory=50M
IndexMemory=25M
MaxNoOfConcurrentTransactions=50
MaxNoOfConcurrentOperations=250
TimeBetweenWatchDogCheck=40000
MaxNoOfOrderedIndexes=1000
MaxNoOfTables=200
MaxNoOfAttributes=250

[ndbd]
HeartbeatIntervalDbDb=600
HeartBeatIntervalDbApi=600
Hostname=$node2
DataDir=/var/lib/mysql-cluster
DataMemory=50M
IndexMemory=25M
MaxNoOfConcurrentTransactions=50
MaxNoOfConcurrentOperations=250
TimeBetweenWatchDogCheck=40000
MaxNoOfOrderedIndexes=1000
MaxNoOfTables=200
MaxNoOfAttributes=250

[ndbd]
HeartbeatIntervalDbDb=600
HeartBeatIntervalDbApi=600
Hostname=$node3
DataDir=/var/lib/mysql-cluster
DataMemory=50M
IndexMemory=25M
MaxNoOfConcurrentTransactions=50
MaxNoOfConcurrentOperations=250
TimeBetweenWatchDogCheck=40000
MaxNoOfOrderedIndexes=1000
MaxNoOfTables=200
MaxNoOfAttributes=250

[ndbd]
HeartbeatIntervalDbDb=600
HeartBeatIntervalDbApi=600
Hostname=$node4
DataDir=/var/lib/mysql-cluster
DataMemory=50M
IndexMemory=25M
MaxNoOfConcurrentTransactions=50
MaxNoOfConcurrentOperations=250
TimeBetweenWatchDogCheck=40000
MaxNoOfOrderedIndexes=1000
MaxNoOfTables=200
MaxNoOfAttributes=250

[mysqld]
[mysqld]
[mysqld]
[mysqld]" >> /var/lib/mysql-cluster/config.ini


# create Ndb.cfg

echo "host=$mgm1" >> /var/lib/mysql-cluster

# edit my.cnf (remember ndbcluster option!)

mv /etc/mysql/my.cnf /etc/mysql/my.cnf.orig
echo "
[client]
port		= 3306
socket		= /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket		= /var/run/mysqld/mysqld.sock
nice		= 0

[mysqld]
user		= mysql
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
port		= 3306
basedir		= /usr
datadir		= /var/lib/mysql
tmpdir		= /tmp
language	= /usr/share/mysql/english
skip-external-locking
bind-address		= 127.0.0.1
key_buffer		= 16M
max_allowed_packet	= 16M
thread_stack		= 128K
thread_cache_size	= 8
myisam-recover		= BACKUP
query_cache_limit       = 1M
query_cache_size        = 16M
expire_logs_days	= 10
max_binlog_size         = 100M

ndbcluster

[mysqldump]
quick
quote-names
max_allowed_packet	= 16M

[mysql]

[isamchk]
key_buffer		= 16M

[MYSQL_CLUSTER]
ndb-connectstring=$mgm1

!includedir /etc/mysql/conf.d/" >> /etc/mysql/my.cnf

# start up the NDB API and MySQL 
# Please note that you MUST have a management node running in order to connect
# the cluster nodes!

/etc/init.d/mysql-ndb start
/etc/init.d/mysql start

